$('document').ready(function () {
    appBosch.iTrainings = 1;
    var dataSource = new kendo.data.DataSource({
        transport: {
            read: {
                url: appBosch.read,
                dataType: "json"
            },
            update: {
                url: appBosch.update,
                dataType: "json"
            },
            parameterMap: function (options, operation) {
                var params = {};
                switch (operation) {
                    case 'update':
                        params = {
                            models: kendo.stringify(options.models[0])
                        };
                        break;
                }
                return params;
            }
        },
        batch: true,
        schema: {
            model: {
                id: "value",
                fields: {
                    nomina: {
                        type: 'string',
                        editable: false
                    },
                    name: {
                        type: 'string',
                        editable: false
                    },
                    calif: {
                        type: 'number',
                        editable: false
                    },
                    date_att: {
                        type: 'date',
                        validation: {
                            required: true,
                            max: new Date()
                        },
                        defaultValue: new Date()
                    },
                    nameTest: {
                        type: 'string',
                        editable: false
                    }
                }
            }
        }
    });

    $("#grid").kendoGrid({
        toolbar: [
            {
                name: "pdf"
            },
            {
                name: "excel"
            }
        ],
        excel: {
            fileName: "Intentos sin fechar.xlsx",
            filterable: true,
            allPages: true
        },
        pdf: {
            allPages: true,
            fileName: "Intentos sin fechar.pdf"
        },
        scrollable: true,
        filterable: true,
        selectable: true,
        navigatable: true,
        resizable: true,
        columnMenu: true,
        sortable: true,
        dataSource: dataSource,
        dataBound: function () {
            appBosch.iTrainings = 1;
        },
        groupable: true,
        columns: [
            {
                title: "#",
                template: '#=appBosch.iTrainings++#',
                width: 50
            },
            {
                field: "nomina",
                title: "Nómina"
            },
            {
                field: "name",
                title: "Asociado",
                hidden: true
            },
            {
                field: 'nameTest',
                title: 'Curso'
            },
            {
                field: "date_att",
                title: "Fecha",
                template: '# console.log(date_att); if (date_att != null) { # <span title="#=kendo.toString(new Date(date_att), "D")#" >#=kendo.toString(new Date(date_att), "d")#</span> # } else { # <span>Sin fecha</span> # } #'
            },
            {
                field: "calif",
                title: "Calificacion"
            },
            {
                command: [
                    {
                        name: "edit",
                        text: {
                            edit: "",
                            update: "",
                            cancel: ""
                        }
                    }
                ],
                width: 100
            }
        ],
        editable: "inline"
    }).data('kendoGrid');
});